var t = require;
var e = module;
var o = exports;
var a,
    i =
        (this && this.__extends) ||
        ((a = function (t, e) {
            return (a =
                Object.setPrototypeOf ||
                ({__proto__: []} instanceof Array &&
                    function (t, e) {
                        t.__proto__ = e;
                    }) ||
                function (t, e) {
                    for (var o in e) Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
                })(t, e);
        }),
        function (t, e) {
            a(t, e);
            function o() {
                this.constructor = t;
            }
            t.prototype = null === e ? Object.create(e) : ((o.prototype = e.prototype), new o());
        }),
    n =
        (this && this.__decorate) ||
        function (t, e, o, a) {
            var i,
                n = arguments.length,
                r = n < 3 ? e : null === a ? (a = Object.getOwnPropertyDescriptor(e, o)) : a;
            if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(t, e, o, a);
            else
                for (var s = t.length - 1; s >= 0; s--)
                    (i = t[s]) && (r = (n < 3 ? i(r) : n > 3 ? i(e, o, r) : i(e, o)) || r);
            return n > 3 && r && Object.defineProperty(e, o, r), r;
        };
Object.defineProperty(o, "__esModule", {value: !0});
var r = t("UIBase"),
    s = t("UIConfig"),
    c = t("UIManager"),
    p = t("BoxReward"),
    l = t("CommonRandom"),
    d = t("RewardItem"),
    u = t("GameEm"),
    h = cc._decorator,
    f = h.ccclass,
    y =
        (h.property,
        h.menu,
        (function (t) {
            i(e, t);
            function e() {
                var e = (null !== t && t.apply(this, arguments)) || this;
                e.playAnimal = null;
                e.list = [];
                return e;
            }
            e.prototype.onShowEnd = function () {
                this.checkBtnView();
                this.makeNewReward();
                EVUIEffView.on(EVUIEffView.checkCostUI, this.checkBtnView.bind(this), this);
            };
            e.prototype.openGuild = function () {
                if (!GuildCache.isOverOnceGuid(GuildCache.oncecheckId[2][8])) {
                    GuildCache.checkKey = GuildCache.oncecheckId[2][8];
                    GuildCache.overOnceGuid(GuildCache.oncecheckId[2][8]);
                    GuildCache.openGuildView();
                }
            };
            e.prototype.onCloseStart = function () {
                for (var t = 0; t < this.list.length; t++) QLooperNode.putNode(this.list[t]);
                this.list.length = 0;
                EVUIEffView.offTarget(this);
            };
            e.prototype._onCloseBgTouchEnd = function () {
                this.closeReward();
            };
            e.prototype.closeReward = function () {
                var t = this;
                this.scheduleOnce(function () {
                    t.checkOpenGuild();
                    t.closeUI();
                });
            };
            e.prototype.checkOpenGuild = function () {
                var t = GuildCache.isOverOnceGuid(GuildCache.oncecheckId[2][8]),
                    e = !GuildCache.isOverOnceGuid(GuildCache.oncecheckId[2][2]);
                if (t && e) {
                    c.default.closeUiByUIID(s.UIID.UIShop);
                    GuildCache.checkKey = GuildCache.oncecheckId[2][2];
                    GuildCache.overOnceGuid(GuildCache.oncecheckId[2][2]);
                    GuildCache.openGuildView();
                }
            };
            e.prototype._onOpenBtnTouchEnd = function () {
                var t = this,
                    e = this.ui_data.data,
                    o = GameDataValue.getShopKey(e.cost_item),
                    a = e.cost_num || 0,
                    i = this.ui_data.id,
                    n = this.ui_data.kind;
                switch (e.cost_item) {
                    case 10:
                        var r = GameDataValue.getShopTimeCount(n, i),
                            p = Date.now() - r,
                            l = e.time_cd || 0;
                        l *= 1e3;
                        var d = {
                            resId: this.ui_data.costId,
                            count: 1,
                            type: 4,
                            rewadJson: {},
                            tip: this.ui_data.tipStr,
                            tip2: "商店看广告购买"
                        };
                        this.ui_data.logData = d;
                        p >= l ? this.resetOpenItem() : c.default.open(s.UIID.UIToast, {msg: "冷却中"});
                        break;
                    default:
                        if (o >= a && a > 0) {
                            var h = {
                                resId: this.ui_data.costId,
                                count: a,
                                type: e.cost_item,
                                rewadJson: {},
                                tip: this.ui_data.tipStr,
                                tip2: "钥匙消耗"
                            };
                            this.ui_data.logData = h;
                            GameDataValue.setShopKey(e.cost_item, o - a);
                            this.resetOpenItem();
                        } else {
                            QReport.send(1 == i ? "220002" : "220003");
                            var f = GameDataValue.getPropCount(u.PropKind.zhuanshi),
                                y = e.diamond_num || 0;
                            f >= y
                                ? c.default.open(s.UIID.UIUseZs, {
                                      cost: y,
                                      cb: function () {
                                          GameDataValue.setPropCount(u.PropKind.zhuanshi, f - y);
                                          var e = {
                                              resId: t.ui_data.costId,
                                              count: y,
                                              type: 1,
                                              rewadJson: {},
                                              tip: t.ui_data.tipStr,
                                              tip2: "钻石消耗"
                                          };
                                          t.ui_data.logData = e;
                                          t.resetOpenItem();
                                      }
                                  })
                                : c.default.open(s.UIID.UIToast, {msg: "钻石不足"});
                        }
                }
            };
            e.prototype.resetOpenItem = function () {
                for (var t = 0; t < this.list.length; t++) QLooperNode.putNode(this.list[t]);
                this.list.length = 0;
                this.openAddRewad(this.playAnimal);
            };
            e.prototype.makeNewReward = function () {
                var t = QLooperNode.getNode(QLooperNode.tag_boxReward);
                t.parent = this._rewardParent;
                t.setPosition(cc.Vec2.ZERO);
                var e = t.getComponent(p.default);
                this.playAnimal = e;
                this.openAddRewad(e);
            };
            e.prototype.setRewordSprite = function () {
                var t = this.ui_data.data;
                this.setRewardDataView(
                    t,
                    this.playAnimal.bomNode.getComponent(cc.Sprite),
                    this.playAnimal.topNode.getComponent(cc.Sprite),
                    this.playAnimal.openNode.getComponent(cc.Sprite)
                );
            };
            e.prototype.setRewardDataView = function (t, e, o, a) {
                switch (t.item_id) {
                    case 3:
                        SpriteView.setBoxBottom(1, e);
                        SpriteView.setBoxTop(1, o);
                        SpriteView.setBoxOpen(1, a);
                        break;
                    case 4:
                        SpriteView.setBoxBottom(2, e);
                        SpriteView.setBoxTop(2, o);
                        SpriteView.setBoxOpen(2, a);
                        break;
                    case 5:
                        SpriteView.setBoxBottom(3, e);
                        SpriteView.setBoxTop(3, o);
                        SpriteView.setBoxOpen(3, a);
                }
            };
            e.prototype.openAddRewad = function (t) {
                var e = this;
                QAudio.play("effect_suitcase_open");
                t.play();
                this._rewardNameLab.$Label.string = "";
                this._quality.$Label.string = "";
                this.setRewordSprite();
                this._btnGroup.active = !1;
                this.scheduleOnce(function () {
                    e.openGuild();
                    e.viewReard(t.rewardNode);
                    e.openViewNode();
                    EVUIEffView.emit(EVUIEffView.updateBoxCount);
                    CacheDataManager.updateCostDataView = !0;
                }, 1);
            };
            e.prototype.openViewNode = function () {
                this._btnGroup.active = !0;
                this.checkBtnView();
            };
            e.prototype.checkBtnView = function () {
                var t = this.ui_data.data;
                this._timeViewNode.active = !1;
                this._hhReward.active = !1;
                switch (t.cost_item) {
                    case 10:
                        this.setBtnCoin(1);
                        this.checkAdReward(t);
                        this._countLab.$Label.string = "免费";
                        break;
                    case 6:
                        this.checkReward(t, 2);
                        break;
                    case 7:
                        this._hhReward.active = !0;
                        this.checkReward(t, 3);
                }
            };
            e.prototype.checkAdReward = function (t) {
                console.log("UIBoxReward ----------------- 检测广告状态", t);
                this._timeViewNode.active = !0;
                this.checkAdView(t);
            };
            e.prototype.checkAdView = function (t) {
                var e = GameDataValue.getShopTimeCount(1, 0),
                    o = Date.now() - e,
                    a = t.time_cd || 0;
                if (o >= (a *= 1e3)) this.setBtnRender(!0);
                else {
                    this._timeViewNode.$TimeViewNode2.checkView(e, a, this.moveTimeCall.bind(this));
                    this.setBtnRender(!1);
                }
            };
            e.prototype.setBtnRender = function (t) {
                for (var e = this._btnBg.getComponentsInChildren(cc.RenderComponent), o = 0; o < e.length; o++)
                    CacheDataManager.setSpriteMat(e[o], t);
            };
            e.prototype.moveTimeCall = function (t) {
                "1" == t && (this._timeViewNode.active = !1);
            };
            e.prototype.checkReward = function (t, e) {
                var o = GameDataValue.getShopKey(t.cost_item),
                    a = t.cost_num || 0;
                if (o >= a && a > 0) {
                    this._countLab.$Label.string = o + "/" + a;
                    this.setBtnCoin(e);
                    this.setBtnRender(!0);
                } else {
                    var i = GameDataValue.getPropCount(u.PropKind.zhuanshi),
                        n = t.diamond_num || 0;
                    this.setBtnRender(i >= n);
                    this._countLab.$Label.string = "" + t.diamond_num;
                    this.setBtnCoin(4);
                }
            };
            e.prototype.setBtnCoin = function (t) {
                SpriteView.setBtnCoin(t, this._rewardBtnSprite.$Sprite);
            };
            e.prototype.getNewRewardData = function () {
                var t = [],
                    e = this.ui_data.rewardData;
                if (e) {
                    if (this.ui_data.data.item_id + "" == "5") {
                        var o = "9005";
                        if ((n = CacheDataManager.getRewardKind("5"))) {
                            GameDataValue.setShopKey(o, GameDataValue.getShopKey(o) + 1);
                            if ((n.reset_times || 0) - GameDataValue.getShopKey(o) <= 0) {
                                GameDataValue.setShopKey(o, 0);
                                return [n.reset_reward];
                            }
                        }
                    }
                    for (var a = 0; a < e.open_num; a++) {
                        var i = this.parseViewCostume(e.open_costume_rate);
                        i && t.push(i);
                    }
                    if (this.ui_data.data.item_id + "" == "5") {
                        var n;
                        o = "9005";
                        if ((n = CacheDataManager.getRewardKind("5")))
                            for (a = 0; a < t.length; a++)
                                if (t[a] + "" == n.reset_reward + "") {
                                    GameDataValue.setShopKey(o, 0);
                                    break;
                                }
                    }
                    return t;
                }
            };
            e.prototype.parseViewCostume = function (t) {
                if (t) {
                    for (var e = t.split("|"), o = new l.default(), a = 0; a < e.length; a++) {
                        var i = e[a].split("_");
                        2 == i.length && o.addVal(parseInt(i[1]), i[0]);
                    }
                    return o.getRandomVal();
                }
                return "";
            };
            e.prototype.getRandTypeKind = function (t) {
                var e = {},
                    o = CacheDataManager.getCostumeup(),
                    a = CacheDataManager.getCostume(),
                    i = [];
                for (var n in o) o[n].quality == t && i.push(n);
                var r = i[Math.floor(Math.random() * i.length)];
                GameDataValue.addEquip(r);
                GameDataValue.setQualityData(a[o[r].costume_id].type, o[r].quality);
                console.log("UIBoxReward ----------------- getRandTypeKindididid", r);
                e.equipData = o[r];
                e.data = {id: r, num: 1};
                return e;
            };
            e.prototype.viewReard = function (t) {
                for (
                    var e = this.getNewRewardData(), o = (e.length, CacheDataManager.getCostume()), a = 0;
                    a < e.length;
                    a++
                ) {
                    var i = QLooperNode.getNode(QLooperNode.tag_rewardItem);
                    i.active = !0;
                    i.parent = t;
                    i.setPosition(cc.v2(0, 0));
                    var n = i.getComponent(d.default);
                    if (n) {
                        var r = this.getRandTypeKind(e[a]),
                            s = r.equipData;
                        if (0 == a && !GuildCache.isOverOnceGuid(GuildCache.oncecheckId[2][4])) {
                            var c = CacheDataManager.getCostumeup();
                            r.data.id = "4001";
                            r.data.num = 1;
                            GameDataValue.addEquip("4001");
                            GameDataValue.setQualityData(o[s.costume_id].type, s.quality);
                            s = c[4001];
                        }
                        if (s) {
                            var p = s.quality;
                            this._rewardNameLab.$Label.string = "" + CacheDataManager.getEquipCostumeUpName(s);
                            SpriteView.setQualityBgLineColor(p, this._quality);
                            SpriteView.setQualityName(p, this._quality.$Label);
                            n.nodeKindItem.setTypeKind(o[s.costume_id].type, p);
                            SpriteView.setTaskSprite(n.iconSprite, o[s.costume_id].icon);
                            SpriteView.setQualityBgLineColor(p, n.bgLine.node);
                            SpriteView.setQualityBgColor(p, n.bgSprite.node);
                            if (this.ui_data && this.ui_data.logData) {
                                var l = this.ui_data.logData;
                                PayData.addLog(l.resId, l.count, l.type, [r.data], l.tip, l.tip2);
                                this.ui_data.logData = null;
                            }
                        }
                        this.list.push(i);
                    }
                }
            };
            return n([f], e);
        })(r.default));
o.default = y;
